<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import dialogMixins from '@/utils/commonDialogMixins'
import DialogEditor from '@/components/DialogEditor/index'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        name: {
          label: '名称',
          placeholder: '请输入参数名'
        },
        type: {
          label: '字典类型',
          placeholder: '请输入字典类型',
          hidden: true
        },
        code: {
          inputType: '字典码',
          label: '字典码',
          hidden: true
        },
        value: {
          label: '字典值',
          hidden: true
        },
        parentId: {
          placeholder: '请输选择所属父类',
          label: '所属父类',
          list: [],
          type: 'list'
        },
        // orderNum: {label: '排序'},
        imagePath: {
          label: '图片',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        },
        remark: {label: '备注'}
      }
    }
  },
  methods: {
    init(id, property, cb) {
      this.dataForm.id = id || 0
      this.initSysDictList()
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('name', 'parentId'),
        initApi: 'systemApi/dictInfo',
        saveApi: 'systemApi/saveDict',
        updateApi: 'systemApi/updateDict',
        objectName: 'dict',
        submitCallback: cb
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    },
    initSysDictList() {

      mRequest('systemApi/getSysDictList', {}, (res) => {
        this.dataFormConfig['parentId'].list = this.R.pathOr([], ['data', 'list'], res)
      })
    }
  }
}
</script>
